<%--
  Created by IntelliJ IDEA.
  User: 32450
  Date: 2024/08/18
  Time: 18:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <%
        String base = request.getContextPath()+"/";
        String url = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+base;
        String enterprise_id = request.getParameter("enterprise_id");
    %>
    <base href="<%=url%>">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>供应链金融平台</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>

<body data-type="generalComponents">
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
            <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                    <span class="tpl-header-list-user-nick">禁言小张</span>
                    <span class="tpl-header-list-user-ico">
              <img src="assets/img/user01.png">
            </span>
                </a>
                <ul class="am-dropdown-content">
                    <li>
                        <a href="index.jsp">
                            <span class="am-icon-power-off"></span> 退出</a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
    <style>
        .am-tabs-bd {
            border: none;
        }

        .am-tabs-bd .am-tab-panel {
            padding: 0
        }
    </style>
</header>
<div class="tpl-page-container tpl-page-header-fixed">
    <div class="tpl-left-nav tpl-left-nav-hover">
        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-table"></i>
                        <span>发票管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu" style="display:block">
                        <li>
                            <a href="invoice-list.jsp" class="active">
                                <i class="am-icon-angle-right"></i>
                                <span>发票总览管理</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title" style="margin-bottom: 4px;">
            发票信息管理
        </div>
        <div class="am-tabs" data-am-tabs>
            <ul class="am-tabs-nav am-nav am-nav-tabs" style="height: 50px;border:none">
                <li class="am-active">
                    <a href="#tab1">基础信息管理</a>
                </li>
                <li>
                    <a id="TabAddress" href="#tab2">邮寄地址管理</a>
                </li>
                <li>
                    <a id="TabEmail" href="#tab3">电子邮箱</a>
                </li>
            </ul>
            <div class="am-tabs-bd">
                <div class="am-tab-panel am-active" id="tab1">
                    <div class="tpl-portlet-components">
                        <div class="tpl-block ">
                            <div class="am-g">
                                <div class="am-u-sm-12">
                                    <form class="am-form">
                                        <table class="am-table am-table-striped am-table-hover table-main">
                                            <thead>
                                            <tr>
                                                <th class="table-title">序号</th>
                                                <th class="table-title">发票抬头</th>
                                                <th class="table-author am-hide-sm-only">税号</th>
                                                <th class="table-author am-hide-sm-only">开户银行</th>
                                                <th class="table-date am-hide-sm-only">开户账号</th>
                                                <th class="table-date am-hide-sm-only">注册固定电话</th>
                                                <th class="table-date am-hide-sm-only">注册场所地址</th>
                                                <th class="table-date am-hide-sm-only">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="doc-modal-list">
                                            <tr data-id="2">
                                                <td class="am-hide-sm-only">
                                                    <span id="BaseData1">1</span>
                                                </td>
                                                <td class="am-hide-sm-only" id="BaseData3">百度科技有限公司
                                                    <span style="background-color: rgba(230, 247, 255, 1);border: 1px solid;color: #1890FF;padding:3px 5px;border-radius: 3px;">默认</span>
                                                </td>
                                                <td class="am-hide-sm-only" id="BaseData4">91110000802100XXXX</td>
                                                <td>
                                                    <div class="editRow" id="BaseData5">中国工商银行</div>
                                                    <input id="BaseData5value" type="text" class="am-form-field editInput" value="中国工商银行"
                                                           style="border: 1px solid #c2cad8;width: 70%;border-radius: 3px;">
                                                </td>
                                                <td class="am-hide-sm-only">
                                                    <div class="editRow" id="BaseData6">12345678998745632</div>
                                                    <input id="BaseData6value" type="text" class="am-form-field editInput"
                                                           value="12345678998745632"
                                                           style="border: 1px solid #c2cad8;width: 70%;border-radius: 3px;">
                                                </td>
                                                <td class="am-hide-sm-only">
                                                    <div class="editRow" id="BaseData7">13888888888</div>
                                                    <input id="BaseData7value" type="text" class="am-form-field editInput"
                                                           value="13888888888"
                                                           style="border: 1px solid #c2cad8;width: 70%;border-radius: 3px;">
                                                </td>
                                                <td class="am-hide-sm-only">
                                                    <div class="editRow" id="BaseData8">北京市海淀区百度大厦</div>
                                                    <input id="BaseData8value" type="text" class="am-form-field editInput"
                                                           value="北京市海淀区百度大厦"
                                                           style="border: 1px solid #c2cad8;width: 70%;border-radius: 3px;">
                                                </td>
                                                <td>
                                                    <div class="am-btn-toolbar">
                                                        <div class="am-btn-group am-btn-group-xs">
                                                            <div class="am-g">
                                                                <div class="am-u-sm-4" id="editBtn">
                                      <span class="am-text-secondary"
                                            style="cursor:pointer;width: 30px;display: inline-block;color:#007bff">
                                        编辑</span>
                                                                </div>
                                                                <div class="am-u-sm-10">
                                        <span id="saveBtn" class=" "
                                              style="cursor:pointer;width: 30px;color:#007bff;display:inline-block">
                                        保存</span>
                                                                    <span id="cancelBtn" class=""
                                                                          style="cursor:pointer;width: 30px;color:#007bff;display:inline-block">
                                        取消</span>
                                                                </div>
                                                                <div class="am-u-sm-1">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <div style="text-align: center;margin-top:40px">
                                            <a class="am-btn am-btn-default" href="invoice-list.jsp?enterprise_id=<%=enterprise_id%>" >返&nbsp;&nbsp;&nbsp;&nbsp;
                                                回
                                            </a>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="am-tab-panel" id="tab2">
                    <div class="tpl-portlet-components">
                        <div class="tpl-block ">
                            <div class="am-g">
                                <div class="am-u-sm-12">
                                    <form class="am-form">
                                        <table class="am-table am-table-striped am-table-hover table-main"
                                               id="table_id_address">
                                            <thead>
                                            <tr>
                                                <th class="table-title">序号</th>
                                                <th class="table-title">收件人</th>
                                                <th class="table-author am-hide-sm-only">联系电话</th>
                                                <th class="table-author am-hide-sm-only">省市区</th>
                                                <th class="table-date am-hide-sm-only">详细地址</th>
                                                <th class="table-date am-hide-sm-only">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="AddressContent">


                                            </tbody>
                                        </table>
                                        <div style="text-align: center;margin-top:40px">
                                            <a class="am-btn am-btn-default" href="invoice-list.jsp?enterprise_id=<%=enterprise_id%>">返&nbsp;&nbsp;&nbsp;&nbsp;
                                                回
                                            </a>
                                            <a id="submitBtn" class="am-btn am-btn-primary" onclick="add_address()"
                                               style="margin-left:20px">新&nbsp;&nbsp;&nbsp;&nbsp; 增
                                            </a>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="am-tab-panel" id="tab3">
                    <div class="tpl-portlet-components">
                        <div class="tpl-block ">
                            <div class="am-g">
                                <div class="am-u-sm-12">
                                    <form class="am-form">
                                        <table class="am-table am-table-striped am-table-hover table-main"
                                               id="table_id_email">
                                            <thead>
                                            <tr>
                                                <th class="table-title">序号</th>
                                                <th class="table-title">邮箱</th>
                                                <th class="table-date am-hide-sm-only">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="emailContent">

                                            </tbody>
                                        </table>
                                        <div style="text-align: center;margin-top:40px">
                                            <a class="am-btn am-btn-default" href="invoice-list.jsp?enterprise_id=<%=enterprise_id%>">返&nbsp;&nbsp;&nbsp;&nbsp;
                                                回
                                            </a>
                                            <a class="am-btn am-btn-primary" onclick="addtmpParam()"
                                               style="margin-left:20px">新&nbsp;&nbsp;&nbsp;&nbsp; 增
                                            </a>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script>


    //penterprise_id:自登录传过来的公司：  对本页面内进行的所有修改基于此
    var jspenterprise_id = "<%=request.getParameter("enterprise_id")%>";

    //   发票
    var cancelBtn = document.getElementById('cancelBtn');
    cancelBtn.style.display = "none";
    var saveBtn = document.getElementById('saveBtn');
    saveBtn.style.display = "none";
    var editBtn = document.getElementById('editBtn');
    var editRow = document.getElementsByClassName('editRow');
    var editInput = document.getElementsByClassName('editInput');
    for (var i = 0; i < editInput.length; i++) {
        editInput[i].style.display = "none";
    }
    // 取消按钮
    $(function () {
        $('#cancelBtn').on('click', function () {
            cancelBtn.style.display = "none";
            editBtn.style.display = "block";
            saveBtn.style.display = "none";
            for (var i = 0; i < editRow.length; i++) {
                editRow[i].style.display = "block";
            }
            for (var i = 0; i < editInput.length; i++) {
                editInput[i].style.display = "none";
            }
        });
    });
    // 保存按钮
    $(function () {
        $('#saveBtn').on('click', function () {
            cancelBtn.style.display = "none";
            saveBtn.style.display = "none";
            editBtn.style.display = "block";
            for (var i = 0; i < editRow.length; i++) {
                editRow[i].style.display = "block";
            }
            for (var i = 0; i < editInput.length; i++) {
                editInput[i].style.display = "none";
            }
        });
    });
    // 编辑按钮
    $(function () {
        $('#editBtn').on('click', function () {
            cancelBtn.style.display = "inline-block";
            saveBtn.style.display = "inline-block";
            editBtn.style.display = "none";
            for (var i = 0; i < editRow.length; i++) {
                editRow[i].style.display = "none";
            }
            for (var i = 0; i < editInput.length; i++) {
                editInput[i].style.display = "block";
            }
        });
    });



    //基础信息管理： 得到BaseData中的元素
    $.get("system/getBaseData",{"enterprise_id":jspenterprise_id},function (baseData) {
        // 选择目标 <td> 元素
        var $td = $('#BaseData3');
        // 提取 <span> 元素
        var $span = $td.find('span');
        // 重新附加 <span> 元素
        $td.append($span);
        JSON.stringify(baseData);
        for (let i = 0; i <baseData.length ; i++) {
            $('#BaseData1').text( baseData[i].id);
            // 更新 <td> 的文本内容，保留 <span> 内容
            $td.contents().filter(function() {
                return this.nodeType === 3; // 过滤出文本节点
            }).first().replaceWith(baseData[i].title); // 替换第一个文本节点
            $('#BaseData4').text(baseData[i].tax_no);
            $('#BaseData5').text(baseData[i].bank_name);
            $('#BaseData5value').val(baseData[i].bank_name);//修改对应value值
            $('#BaseData6').text(baseData[i].bank_account);
            $('#BaseData6value').val(baseData[i].bank_account);
            $('#BaseData7').text(baseData[i].phone);
            $('#BaseData7value').val(baseData[i].phone);
            $('#BaseData8').text(baseData[i].address);
            $('#BaseData8value').val(baseData[i].address);
        }
    });
    //基础信息管理： 修改BaseData数据
    $('#saveBtn').click(function () {
        var jspbank_name =$('#BaseData5value').val();
        var jspbank_account=$('#BaseData6value').val();
        var jspphone=$('#BaseData7value').val();
        var jspaddress=$('#BaseData8value').val();
        //税号唯一，作为修改锚点
        var jsptax_no=$('#BaseData4').text();
        $.get("system/updateBaseData",
            {
                "bank_name":jspbank_name,
                "bank_account":jspbank_account,
                "phone": jspphone,
                "address":jspaddress,
                "tax_no":jsptax_no
            },function (uncertain) {
                if (uncertain!=0){
                    $('#BaseData5').text(jspbank_name);
                    $('#BaseData6').text(jspbank_account);
                    $('#BaseData7').text(jspphone);
                    $('#BaseData8').text(jspaddress);
                    $('#BaseData5value').val(jspbank_name);//修改对应value值
                    $('#BaseData6value').val(jspbank_account);
                    $('#BaseData7value').val(jspphone);
                    $('#BaseData8value').val(jspaddress);
                }else {
                    alert("修改失败");
                }
            });
    });



    // 邮寄地址管理：查找Adress数据在页面展示
    $("#TabAddress").click(displayinfo());
    function displayinfo() {
        $.get("system/queryAddress",{"enterprise_id":jspenterprise_id},function (address) {
            JSON.stringify(address);
            // eval("var books="+books);
            let Table = document.getElementById("table_id_address");
            //清除
            while (Table.rows.length > 1) {
                Table.deleteRow(1);
            }
            for(var i=0;i<address.length;i++){
                let rowsNum = Table.rows.length - 1;//保证是在末尾添加新行
                NewRow = Table.insertRow(); //添加行
                ID = NewRow.insertCell(); //添加列
                Name = NewRow.insertCell();//
                NO = NewRow.insertCell();
                Type = NewRow.insertCell();
                defaultV = NewRow.insertCell();
                operate = NewRow.insertCell();
                //属性赋值
                ID.innerHTML =   i+1;
                Name.innerHTML = "<input id=Name" + (rowsNum + 1) + " style='width: 120px;' type='text' value='"+address[i].addressee+"'  />";
                //为输入框设置一个唯一的 id，格式为 Name 加上当前行数加 1。例如，如果 rowsNum 是 2，ID 将是 Name3
                NO.innerHTML = "<input id=No" + (rowsNum + 1) + "  style='width: 120px;' type='text' value='"+address[i].phone+"' />";
                Type.innerHTML = "<input id=Type" + (rowsNum + 1) + "  style='width: 120px;' type='text' value='"+address[i].area+"' />";
                defaultV.innerHTML = "<input id=defaultV" + (rowsNum + 1) + "  style='width: 120px;' type='text' value='"+address[i].address_detail+"' />";
                if (address[i].default_status==="默认"){
                    operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;" class="insert" onclick="editAddress('+address[i].id+')">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;" onclick="changeStatus('+address[i].id+')">默认</a></div>';
                }else {
                    operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;" class="insert" onclick="editAddress('+address[i].id+')">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;" onclick="changeStatus('+address[i].id+')">设为默认</a></div>';
                }
                $("#Name" + (rowsNum + 1)).attr("disabled", true);
                $("#No" + (rowsNum + 1)).attr("disabled", true);
                $("#Type" + (rowsNum + 1)).attr("disabled", true);
                $("#defaultV" + (rowsNum + 1)).attr("disabled", true);
            }
        });//
        // $("#AddressContent").empty();
        // $.get("system/queryAddress",{"enterprise_id":1},function (address) {
        //     JSON.stringify(address);
        //     // eval("var books="+books);
        //     for(var i=0;i<address.length;i++){
        //
        //         $("<tr>" +
        //             "<td>"+(i+1)+"</td>" +
        //             "<td>"+address[i].addressee+"</td>" +
        //             "<td>"+address[i].phone+"</td>" +
        //             "<td>"+address[i].area+"</td>" +
        //             "<td>"+address[i].address_detail+"</td>" +
        //             "<td><a class='ready-a' style='cursor:pointer;color:#007bff;'  data-id='"+address[i].id +"' data-phone='" + address[i].phone + "' data-area='" + address[i].area + "' data-address-detail='" + address[i].address_detail + "' onclick='editAddress("+(i+1)+")'>编辑</a>&nbsp;&nbsp;<a style='cursor:pointer;color:#007bff;'>设为默认</a></td>"+
        //             "</tr>").appendTo("#AddressContent");
        //     }
        // });
    }
    // 添加邮寄地址
    function add_address() {
        let Table = document.getElementById("table_id_address");
        let rowsNum = Table.rows.length - 1;//保证是在末尾添加新行
        NewRow = Table.insertRow(); //添加行
        ID = NewRow.insertCell(); //添加列
        Name = NewRow.insertCell();//
        NO = NewRow.insertCell();
        Type = NewRow.insertCell();
        defaultV = NewRow.insertCell();
        operate = NewRow.insertCell();
        //属性赋值
        ID.innerHTML = rowsNum + 1;
        Name.innerHTML = "<input id=Name" + (rowsNum + 1) + " style='width: 120px;' type='text' />";
        //为输入框设置一个唯一的 id，格式为 Name 加上当前行数加 1。例如，如果 rowsNum 是 2，ID 将是 Name3
        NO.innerHTML = "<input id=No" + (rowsNum + 1) + "  style='width: 120px;' type='text' />";
        Type.innerHTML = "<input id=Type" + (rowsNum + 1) + "  style='width: 120px;' type='text' />";
        defaultV.innerHTML = "<input id=defaultV" + (rowsNum + 1) + "  style='width: 120px;' type='text' />";
        operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;" class="insert" onclick="saveAddress();">保存</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;"  onclick="removeRow(this)">取消</a></div>';
    }
    //在添加数据时的取消按钮处理
    function removeRow(element) {
            var row = element.closest("tr"); // 找到当前行
            if (row) {
                row.remove(); // 删除当前行
            }
        }
    //添加数据填入数据库中的Address表,保存
    function saveAddress() {
        let td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        //获取行索引，修改input样式，其中parentElement和table中的标签层级相关，不是一成不变
        let key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
        $("#Name" + key).attr("disabled", true);
        //使用 jQuery 的选择器 $() 来选择一个 HTML 元素。选择器的字符串是 "#Name" 和变量 key 的值的拼接结果。
        // 例如，如果 key 的值是 3，则选择器字符串是 "#Name3"。这会选择具有 id 为 Name3 的元素。
        $("#No" + key).attr("disabled", true);
        $("#Type" + key).attr("disabled", true);
        $("#defaultV" + key).attr("disabled", true);

        //获得动态添加的输入框的内容
        let  jspaddressee   =  $("#Name" + key).val();
        let  jspphone   =  $("#No" + key).val();
        let  jsparea  =  $("#Type" + key).val();
        let  jspaddress_detail  =  $("#defaultV" + key).val();
        $.get("system/insertAddress",
            {
                "enterprise_id":jspenterprise_id,
                "addressee":jspaddressee,
                "phone":jspphone,
                "area":jsparea,
                "address_detail":jspaddress_detail
            },function(uncertain) {
                if(uncertain!=0){
                    alert("添加成功")
                    //重新加载页面
                    displayinfo();
                }else {
                    alert("添加失败")
                }
            });

    }
    //编辑
    function editAddress(id) {
        let td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        let key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
            $("#Name" + key).attr("disabled", false);
            $("#No" + key).attr("disabled", false);
            $("#Type" + key).attr("disabled", false);
            $("#defaultV" + key).attr("disabled", false);
            var div1 = $("#operate" + key);
             div1[0].innerHTML = '<a style="cursor:pointer;color:#007bff;"  onclick="saveUpdateAddress('+id+');">保存</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;"  onclick="Cancel('+id+');">取消</a>';


         // 将 id 存储在操作 div 的 data 属性中
    }
    //编辑后点击取消选项时的处理
    function Cancel(id) {
       displayinfo();
    }
    // 邮寄地址管理  修改  Address数据
    function saveUpdateAddress(id) {
        let td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        //获取行索引，修改input样式，其中parentElement和table中的标签层级相关，不是一成不变
        let key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
        $("#Name" + key).attr("disabled", true);
        //使用 jQuery 的选择器 $() 来选择一个 HTML 元素。选择器的字符串是 "#Name" 和变量 key 的值的拼接结果。
        // 例如，如果 key 的值是 3，则选择器字符串是 "#Name3"。这会选择具有 id 为 Name3 的元素。
        $("#No" + key).attr("disabled", true);
        $("#Type" + key).attr("disabled", true);
        $("#defaultV" + key).attr("disabled", true);

        //获得动态添加的输入框的内容
        let  jspaddressee   =  $("#Name" + key).val();
        let  jspphone   =  $("#No" + key).val();
        let  jsparea  =  $("#Type" + key).val();
        let  jspaddress_detail  =  $("#defaultV" + key).val();
        let Addressid;
        //在页面新添加到数据进行编辑
        // if (id===null ||id === undefined) {
        //     $.get("system/queryAllAddress",function (num) {
        //         Addressid=num.length;
        //         $.get("system/updateAddress",
        //             {   "id":Addressid,
        //                 "enterprise_id":1,//暂时的值
        //                 "addressee":jspaddressee,
        //                 "phone":jspphone,
        //                 "area":jsparea,
        //                 "address_detail":jspaddress_detail
        //             },function(uncertain) {
        //                 if(uncertain!=0){
        //                     alert("编辑成功")
        //                     displayinfo();
        //                 }else {
        //                     alert("编辑失败")
        //                 }
        //             });
        //     })
        //     //自数据库搜出的数据进行编辑
        // }else {
            $.get("system/updateAddress",
                {   "id":id,
                    "enterprise_id":jspenterprise_id,
                    "addressee":jspaddressee,
                    "phone":jspphone,
                    "area":jsparea,
                    "address_detail":jspaddress_detail
                },function(uncertain) {
                    if(uncertain!=0){
                        alert("编辑成功")
                        displayinfo();
                    }else {
                        alert("编辑失败")
                    }
                });
        // }
    }
    // 邮箱：默认设置
    function changeStatus(id){
        let td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        // if (id===null ||id === undefined) {
        //  //页面新增内容设置默认
        //             let  jspid;
        //         $.get("system/queryAllAddress",function (address) {
        //             jspid=address.length;
        //             $.get("system/changeStatus",{"enterprise_id":1,"id":jspid},function (uncsrtain) {
        //                         if (uncsrtain!=0){
        //                             td.innerHTML = '<span >默认</span>'; // 改默认
        //                             displayinfo();
        //                         }else {
        //                             alert("修改失败")
        //                         }
        //             });
        //         });
        // }else {
            $.get("system/changeStatus",{"enterprise_id":jspenterprise_id,"id":id},function (uncsrtain) {
                if (uncsrtain!=0){
                    displayinfo();
                }else {
                    alert("修改失败")
                }
            });
        //}
    }



    //电子邮箱管理：   查找Email数据并页面展示
    $("#TabEmail").click(displayEmail());
    function displayEmail() {
        $.get("system/queryEmail",{"enterprise_id":jspenterprise_id},function (email) {
            JSON.stringify(email);
            var Table = document.getElementById("table_id_email");
            while (Table.rows.length > 1) {
                Table.deleteRow(1);
            }
            for (let i = 0; i <email.length ; i++) {
                let rowsNum = Table.rows.length - 1;
                NewRow = Table.insertRow(); //添加行
                ID2 = NewRow.insertCell(); //添加列
                Name2 = NewRow.insertCell();
                operate2 = NewRow.insertCell();
                //属性赋值
                ID2.innerHTML = i+ 1;
                Name2.innerHTML = "<input id=Name2" + (rowsNum + 1) + " style='width:120px' type='text' value='"+email[i].email_detail+"' />";
                $("#Name2" + (rowsNum + 1)).attr("disabled", true);
                if (email[i].default_status==="默认") {
                    operate2.innerHTML = '<div id=operate2' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="editInterfaceParam('+email[i].id+')">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;"  onclick="changeEStatus('+email[i].id+')">默认</a></div>';

                }else {
                    operate2.innerHTML = '<div id=operate2' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="editInterfaceParam('+email[i].id+')">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;" onclick="changeEStatus('+email[i].id+')">设为默认</a></div>';

                }

            }
        });
    }
    // 电子邮箱
    function addtmpParam() {
        var Table = document.getElementById("table_id_email");
        var rowsNum = Table.rows.length - 1;
        NewRow2 = Table.insertRow(); //添加行
        ID2 = NewRow2.insertCell(); //添加列
        Name2 = NewRow2.insertCell();
        // NO = NewRow2.insertCell();
        // Type = NewRow2.insertCell();
        // defaultV = NewRow2.insertCell();
        operate2 = NewRow2.insertCell();
        //属性赋值
        ID2.innerHTML = rowsNum + 1;
        Name2.innerHTML = "<input id=Name2" + (rowsNum + 1) + " style='width:120px' type='text' />";
        // NO.innerHTML = "<input id=No" +  (rowsNum + 1) +"  style='width: 80px;' type='text' />";
        operate2.innerHTML = '<div id=operate2' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="saveInterfaceParam();">保存</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;"   onclick="removeRow(this)">取消</a></div>';
    }


    //新增电子邮箱内容  保存
    function saveInterfaceParam() {
        var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        //获取行索引，修改input样式，其中parentElement和table中的标签层级相关，不是一成不变
        var key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
        $("#Name2" + key).attr("disabled", true);
        var div1 = $("#operate2" + key);
        let  jspemail_detail  =  $("#Name2" + key).val();
        $.get("system/insertEmail",
            {
                "enterprise_id":jspenterprise_id,
                "email_detail":jspemail_detail
            },
            function (email) {
                if (email!=0){
                    alert("添加成功");
                    displayEmail();
                } else {
                    alert("添加失败");
                }
            })

    }

    function editInterfaceParam(id) {
        var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        var key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
        $("#Name2" + key).attr("disabled", false);
        var div1 = $("#operate2" + key);
        div1[0].innerHTML = '<a style="cursor:pointer;color:#007bff;"  onclick="saveEmail('+id+');">保存</a>&nbsp;&nbsp;<a style="cursor:pointer;color:#007bff;"  onclick="CancelE('+id+');">取消</a>';
    }
    //取消  编辑
    function CancelE(id) {
       displayEmail();
    }
    //新增电子邮箱内容保存  分情况
    function saveEmail(id) {
        var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
        //获取行索引，修改input样式，其中parentElement和table中的标签层级相关，不是一成不变
        var key = td.parentElement.parentElement.parentElement.innerText.split("\n")[0].trim();
        $("#Name2" + key).attr("disabled", true);
        var div1 = $("#operate2" + key);
        let jspemail_detail = $("#Name2" + key).val();
            $.get("system/updateEmail",
                {
                    "id":id,
                    "enterprise_id": jspenterprise_id,
                    "email_detail": jspemail_detail
                },
                function (email) {
                    if (email != 0) {
                        alert("修改成功");
                        displayEmail();
                    } else {
                        alert("修改失败");
                        displayEmail();
                    }
                });
        }

    // 邮箱：默认设置
    function changeEStatus(id){
        let td = event.srcElement;
        $.get("system/changeEStatus",{"enterprise_id":jspenterprise_id,"id":id},function (uncsrtain) {
            if (uncsrtain!=0){
               displayEmail();
            }else {
                alert("修改失败");
                displayEmail();
            }
        });

    }
</script>
</body>

</html>